'use strict'

define(['jquery', 'bootstrap', 'select2', 'shiftform', 'validate', 'validate.en', 'datetimepicker'], function ($) {
  return {
  
    init: function () {
      this.initPage();
    },
  
    initPage: function () {
    	

	    $('select[name="transMean"]').select2({
	      theme: "classic",
	      placeholder: '请选择运输工具',
	      minimumResultsForSearch: -1,
	      allowClear: true
	    });
	    
	    $('select[name="vehicleStatus"]').select2({
	        theme: "classic",
	        placeholder: '请选择车辆状态',
	        minimumResultsForSearch: -1,
	        allowClear: true
	      });
	    
	    $('select[name="carOwnership"]').select2({
	        theme: "classic",
	        placeholder: '请选择车辆所有权',
	        minimumResultsForSearch: -1,
	        allowClear: true
	      });
	    
	    $('select[name="trailerType"]').select2({
	        theme: "classic",
	        placeholder: '挂车类型',
	        minimumResultsForSearch: -1,
	        allowClear: true
	      });

	    $('.date').datetimepicker({
	      format: 'yyyy-mm-dd',
	      autoclose: true,
	      language: 'zh-CN',
	      todayBtn: 'linked',
	      startDate: '${today}',
	      todayHighlight: true,
	      pickerPosition: 'bottom-right',
	      minView: 'month'
	    });
    	
	    $('.month').datetimepicker({  
	      format: 'yyyy-mm',
	      autoclose: true,  
	      weekStart: 1,  
	      startView: 3,  
	      minView: 3,  
	      forceParse: false,  
	      language: 'zh-CN'  
	    });
  
      var submitChange = $('input[name="submitChange"]').val();
      if(submitChange == 'true') {
    	  setTimeout(function(){
              window.location.href = window.__CTX__.root + "/vehicle-sources?status=QUALIFIED&synchronize=true";
            }, 2500)
      }
      
      $('select[name="transMean"], select[name="vehicleStatus"]').change(function() {
  		  $('input[name="locked"]').val("true");
  	  })
	  
  	  $('form[data-validate="true"]').bt_validate()  //bind validate
      
    }

  }
})